home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Disk / moni / FileX-src.lha / FileX-src / filexmenu.c < prev    next >
C/C++ Source or Header  |  2003-09-20  |  10KB  |  345 lines

  1. #include "FilexStructs.h"
  2. #include "FileXStrings.h"
  3. #include "allprotos.h"
  4.  
  5. #define AREXXSTARTMENU 99
  6.  
  7. static ULONG displaymenuids[4] = {
  8.     SHIFTMENU(3)+SHIFTITEM(2)+SHIFTSUB(1),
  9.     SHIFTMENU(3)+SHIFTITEM(2)+SHIFTSUB(0),
  10.     SHIFTMENU(3)+SHIFTITEM(2)+SHIFTSUB(2),
  11.     SHIFTMENU(3)+SHIFTITEM(2)+SHIFTSUB(4)    };
  12.  
  13. /* Vergebene Shortcuts:
  14.  * System:
  15.  * N: New
  16.  * O: Open
  17.  * S: Save
  18.  * A: Save as
  19.  * P: Print
  20.  * Q: Quit
  21.  * X: Cut
  22.  * C: Copy
  23.  * V: Paste
  24.  * Z: Undo
  25.  * F: Search
  26.  *
  27.  * Eigene:
  28.  * 
  29.  * ?: About
  30.  * I: Insert
  31.  * M: Mark Block
  32.  * T: Redo
  33.  * G: Grab memory
  34.  * J: Jump to byte
  35.  * R: Replace
  36.  * D: Append
  37.  * K: Mark location
  38.  * L: Jump to location
  39.  * U: Miscellaneous
  40.  * W: Adjust Windowsize
  41.  * Y: Iconify
  42.  * H: Commandshell
  43.  * ^: Fill
  44.  */
  45.  
  46. struct Menu *FileXMenus;
  47.  
  48. static struct NewMenu NewMenus[] = {
  49.       NM_TITLE,   MSG_MENU_PROJECT, NULL, 0, NULL, NULL,
  50.         NM_ITEM, MSG_MENU_PROJECT_NEW, 0, 0, 0L, NULL,
  51. /*        NM_ITEM, "Test", "Shit", NM_COMMANDSTRING, 0L, (APTR)1L,*/
  52.         NM_ITEM, MSG_MENU_PROJECT_OPEN, 0, 0, 0L, NULL,
  53.         NM_ITEM, MSG_MENU_PROJECT_OPENPREVIOUSLOADED, 0, 0, 0L, NULL,
  54.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  55.         NM_ITEM, MSG_MENU_PROJECT_SAVE, 0, 0, 0L, NULL,
  56.         NM_ITEM, MSG_MENU_PROJECT_SAVEAS, 0, 0, 0L, NULL,
  57.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  58.         NM_ITEM, MSG_MENU_VIEW, NULL, 0, NULL, NULL,
  59.             NM_SUB, MSG_MENU_VIEW_NEW, NULL, 0, 0L, NULL,
  60.             NM_SUB, MSG_MENU_VIEW_SPLIT, NULL, 0, 0L, NULL,
  61.             NM_SUB, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  62.             NM_SUB, MSG_MENU_VIEW_NEXT, NULL, 0, 0L, NULL,
  63.             NM_SUB, MSG_MENU_VIEW_PREVIOUS, NULL, 0, 0L, NULL,
  64.             NM_SUB, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  65.             NM_SUB, MSG_MENU_VIEW_EXPAND, NULL, 0, 0L, NULL,
  66.             NM_SUB, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  67.             NM_SUB, MSG_MENU_VIEW_GROW, NULL, 0, 0L, NULL,
  68.             NM_SUB, MSG_MENU_VIEW_SHRINK, NULL, 0, 0L, NULL,
  69.             NM_SUB, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  70.             NM_SUB, MSG_MENU_VIEW_SAVE_AND_CLOSE, NULL, 0, 0L, NULL,
  71.             NM_SUB, MSG_MENU_VIEW_CLOSE, NULL, 0, 0L, NULL,
  72.         NM_ITEM, MSG_MENU_WINDOW, NULL, 0, NULL, NULL,
  73.             NM_SUB, MSG_MENU_WINDOW_NEW, NULL, 0, 0L, NULL,
  74.             NM_SUB, MSG_MENU_WINDOW_SPLIT, NULL, 0, 0L, NULL,
  75.             NM_SUB, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  76.             NM_SUB, MSG_MENU_WINDOW_NEXT, NULL, 0, 0L, NULL,
  77.             NM_SUB, MSG_MENU_WINDOW_PREVIOUS, NULL, 0, 0L, NULL,
  78.             NM_SUB, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  79.             NM_SUB, MSG_MENU_WINDOW_CLOSE, NULL, 0, 0L, NULL,
  80.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  81.         NM_ITEM, MSG_MENU_PROJECT_GRABMEMORY, 0, 0, 0L, NULL,
  82.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  83.         NM_ITEM, MSG_MENU_PROJECT_PRINT, 0, 0, 0L, NULL,
  84.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  85.         NM_ITEM, MSG_MENU_PROJECT_ICONIFY, 0, 0, 0L, NULL,
  86.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  87.         NM_ITEM, MSG_MENU_PROJECT_ABOUT, 0, 0, 0L, NULL,
  88.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  89.         NM_ITEM, MSG_MENU_PROJECT_QUIT, 0, 0, 0L, NULL,
  90.     NM_TITLE, MSG_MENU_EDIT, NULL, 0, NULL, NULL,
  91.         NM_ITEM, MSG_MENU_EDIT_MARKBLOCK, 0, 0, 0L, NULL,
  92.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  93.         NM_ITEM, MSG_MENU_EDIT_CUT, 0, 0, 0L, NULL,
  94.         NM_ITEM, MSG_MENU_EDIT_COPY, 0, 0, 0L, NULL,
  95.         NM_ITEM, MSG_MENU_EDIT_FILL, 0, 0, 0L, NULL,
  96.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  97.         NM_ITEM, MSG_MENU_EDIT_PASTE, 0, 0, 0L, NULL,
  98.         NM_ITEM, MSG_MENU_EDIT_INSERT, 0, 0, 0L, NULL,
  99.         NM_ITEM, MSG_MENU_EDIT_APPEND, 0, 0, 0L, NULL,
  100.         NM_ITEM, MSG_MENU_EDIT_PRINT, 0, 0, 0L, NULL,
  101.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  102.         NM_ITEM, MSG_MENU_EDIT_LOADBLOCK, NULL, 0, 0L, NULL,
  103.         NM_ITEM, MSG_MENU_EDIT_SAVEBLOCK, NULL, 0, 0L, NULL,
  104.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  105.         NM_ITEM, MSG_MENU_EDIT_UNDO, 0, 0, 0L, NULL,
  106.         NM_ITEM, MSG_MENU_EDIT_REDO, 0, 0, 0L, NULL,
  107.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  108.         NM_ITEM, MSG_MENU_EDIT_SWITCH, 0, 0, 0L, NULL,
  109.     NM_TITLE, MSG_MENU_SEARCH, NULL, 0, NULL, NULL,
  110.         NM_ITEM, MSG_MENU_SEARCH_SEARCH, 0, 0, 0L, NULL,
  111.         NM_ITEM, MSG_MENU_SEARCH_REPLACE, 0, 0, 0L, NULL,
  112.         NM_ITEM, MSG_MENU_SEARCH_REPLACENEXT, 0, 0, 0L, NULL,
  113.         NM_ITEM, MSG_MENU_SEARCH_REPLACEPREVIOUS, 0, 0, 0L, NULL,
  114.     NM_TITLE, MSG_MENU_SETTING, NULL, 0, NULL, NULL,
  115.         NM_ITEM, MSG_MENU_SETTINGS_ADJUSTWINDOW, 0, 0, 0L, NULL,
  116.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  117.         NM_ITEM, MSG_MENU_SETTINGS_DISPLAY, NULL, 0, NULL, NULL,
  118.             NM_SUB, MSG_MENU_SETTINGS_DISPLAY_CHARACTERS, NULL, CHECKIT|MENUTOGGLE, 22L, NULL,
  119.             NM_SUB, MSG_MENU_SETTINGS_DISPLAY_ASCII,NULL, CHECKIT|CHECKED|MENUTOGGLE, 21L, NULL,
  120.             NM_SUB, MSG_MENU_SETTINGS_DISPLAY_ALL,NULL, CHECKIT|MENUTOGGLE, 19L, NULL,
  121.             NM_SUB, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  122.             NM_SUB, MSG_MENU_SETTINGS_DISPLAY_USERDEFINED, NULL, CHECKIT|MENUTOGGLE, 7L, NULL,
  123.             NM_SUB, MSG_MENU_SETTINGS_DISPLAY_LOAD, NULL, 0, 0L, NULL,
  124.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  125.         NM_ITEM, MSG_MENU_SETTINGS_FONT, 0, 0, 0L, NULL,
  126.         NM_ITEM, MSG_MENU_SETTINGS_SCREEN, NULL, 0, 0L, NULL,
  127.             NM_SUB, MSG_MENU_SETTINGS_SCREEN_DEFAULTPUBLIC,NULL, NULL, 0L, NULL,
  128.             NM_SUB, MSG_MENU_SETTINGS_SCREEN_WORKBENCH,NULL, NULL, 0L, NULL,
  129.             NM_SUB, MSG_MENU_SETTINGS_SCREEN_PUBLIC,NULL, NULL, 0L, NULL,
  130.             NM_SUB, MSG_MENU_SETTINGS_SCREEN_OWNPUBLIC,NULL, NULL, 0L, NULL,
  131.         NM_ITEM, MSG_MENU_SETTINGS_PALETTE, 0, 0, 0L, NULL,
  132.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  133.         NM_ITEM, MSG_MENU_SETTINGS_MISCELLANEOUS,0, 0, 0L, NULL,
  134.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  135.         NM_ITEM, MSG_MENU_SETTINGS_LOADSETTINGS, NULL, 0, 0L, NULL,
  136.         NM_ITEM, MSG_MENU_SETTINGS_SAVESETTINGS, NULL, 0, 0L, NULL,
  137.         NM_ITEM, MSG_MENU_SETTINGS_SAVESETTINGSAS, NULL, 0, 0L, NULL,
  138.     NM_TITLE, MSG_MENU_MOVE, NULL, 0, NULL, NULL,
  139.         NM_ITEM, MSG_MENU_MOVE_JUMPTOBYTE, 0, 0, 0L, NULL,
  140.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  141.         NM_ITEM, MSG_MENU_MOVE_MARKLOCATION, 0, 0, 0L, NULL,
  142.         NM_ITEM, MSG_MENU_MOVE_JUMPTOMARK, 0, 0, 0L, NULL,
  143.     NM_TITLE, MSG_MENU_AREXX, NULL, 0, NULL, NULL,
  144.         NM_ITEM, MSG_MENU_AREXX_COMMANDSHELL, 0, 0, 0L, NULL,
  145.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  146.         NM_ITEM, MSG_MENU_AREXX_EXECUTECOMMAND,0, 0, 0L, NULL,
  147.         NM_ITEM, MSG_MENU_AREXX_ASSIGNCOMMAND,0, 0, 0L, NULL,
  148.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  149.         NM_ITEM, 0, (STRPTR)"0", 0, 0L, (APTR)1L,
  150.         NM_ITEM, 0, (STRPTR)"1", 0, 0L, (APTR)1L,
  151.         NM_ITEM, 0, (STRPTR)"2", 0, 0L, (APTR)1L,
  152.         NM_ITEM, 0, (STRPTR)"3", 0, 0L, (APTR)1L,
  153.         NM_ITEM, 0, (STRPTR)"4", 0, 0L, (APTR)1L,
  154.         NM_ITEM, 0, (STRPTR)"5", 0, 0L, (APTR)1L,
  155.         NM_ITEM, 0, (STRPTR)"6", 0, 0L, (APTR)1L,
  156.         NM_ITEM, 0, (STRPTR)"7", 0, 0L, (APTR)1L,
  157.         NM_ITEM, 0, (STRPTR)"8", 0, 0L, (APTR)1L,
  158.         NM_ITEM, 0, (STRPTR)"9", 0, 0L, (APTR)1L,
  159.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  160.         NM_ITEM, MSG_MENU_AREXX_LOADCOMMANDS, NULL, 0, 0L, NULL,
  161.         NM_ITEM, MSG_MENU_AREXX_SAVECOMMANDS,NULL, 0, 0L, NULL,
  162.         NM_ITEM, MSG_MENU_AREXX_SAVECOMMANDSAS,NULL, 0, 0L, NULL,
  163.     NM_TITLE, MSG_MENU_MISC, NULL, 0, NULL, NULL,
  164.         NM_ITEM, MSG_MENU_MISC_OPENCALC, NULL, 0, 0L, NULL,
  165.         NM_ITEM, MSG_MENU_MISC_OPENCLIPCONV, NULL, 0, 0L, NULL,
  166.     NM_END, NULL, NULL, 0, 0L, NULL };
  167.  
  168. /*
  169.  * void SetEmptyARexxMenu( WORD Number )
  170.  * 
  171.  * Setzt ein ARexxMenu auf "Empty Command #x".
  172.  */
  173.  
  174. void SetEmptyARexxMenu( WORD Number )
  175. {
  176.     UBYTE *Str = GetStr( MSG_MENU_AREXX_EMPTYCOMMANDX );
  177.  
  178.     if( arexxcommands[ Number ] )
  179.         FreeVec( arexxcommands[ Number ] );
  180.  
  181.     if( arexxcommands[ Number ] = AllocVec( strlen( Str ) + 1 ,MEMF_ANY ))
  182.     {
  183.         sprintf( arexxcommands[ Number ], Str, (WORD) Number );
  184.  
  185.         NewMenus[ AREXXSTARTMENU + Number ].nm_Label = arexxcommands[ Number ];
  186.  
  187.         arexxcommandused[ Number ] = FALSE;
  188.     }
  189. }
  190.  
  191.  
  192. /*
  193.  * void SetARexxMenu( WORD Number, UBYTE *Name )
  194.  * 
  195.  * Setzt ein ARexxMenu auf eine bestimmte Zeichenkette.
  196.  */
  197.  
  198. void SetARexxMenu( WORD Number, UBYTE *Name )
  199. {
  200.     if( arexxcommands[ Number ] )
  201.         FreeVec( arexxcommands[ Number ] );
  202.  
  203.     if( arexxcommands[ Number ] = AllocVec( strlen( Name ) + 1, MEMF_ANY ))
  204.     {
  205.         strcpy( arexxcommands[ Number ], Name );
  206.  
  207.         arexxcommandused[ Number ] = TRUE;
  208.  
  209.         NewMenus[ AREXXSTARTMENU + Number ].nm_Label = FilePart( arexxcommands[ Number ]);
  210.     }
  211. }
  212.  
  213.  
  214. /*
  215.  * void LocalizeMenus( void )
  216.  * 
  217.  * Lokalisiert die Menus
  218.  */
  219.  
  220. void LocalizeMenus( void )
  221. {
  222.     struct NewMenu *NewMenu = NewMenus;
  223.     STRPTR Shortcut, Label;
  224.  
  225.     while( NewMenu->nm_Type != NM_END )
  226.     {
  227.         if(( NewMenu->nm_Label != NM_BARLABEL ) && ( !NewMenu->nm_UserData ))
  228.         {
  229.             Shortcut = GetStr( NewMenu->nm_Label );
  230.  
  231.             if(Shortcut[0] && !Shortcut[1])
  232.                 Label = Shortcut + 2;
  233.             else
  234.             {
  235.                 Label        = Shortcut;
  236.                 Shortcut    = NULL;
  237.             }
  238.  
  239.             switch(NewMenu->nm_Type)
  240.             {
  241.                 case NM_ITEM:
  242.                 case NM_SUB:
  243.                     NewMenu->nm_CommKey = Shortcut;
  244.                     break;
  245.             }
  246.  
  247.             NewMenu->nm_Label = Label;
  248.         }
  249.  
  250.         NewMenu++;
  251.     }
  252. }
  253.  
  254.  
  255. /*
  256.  * void MyFreeMenus( void )
  257.  * 
  258.  * Entfernt die Menus von Fenster und gibt sie frei.
  259.  */
  260.  
  261. void MyFreeMenus( void )
  262. {
  263.     if(FileXMenus)
  264.     {
  265.         struct DisplayInhalt *DI;
  266.  
  267.         DI = (struct DisplayInhalt *)DisplayInhaltList.lh_Head;
  268.  
  269.         while( DI != ( struct DisplayInhalt * )&DisplayInhaltList.lh_Tail )
  270.         {
  271.             if( DI->Wnd )
  272.                 ClearMenuStrip(DI->Wnd);
  273.  
  274.             DI = ( struct DisplayInhalt *)DI->Node.ln_Succ;
  275.         }
  276.  
  277.  
  278.         FreeMenus(FileXMenus);
  279.         FileXMenus = NULL;
  280.     }
  281. }
  282.  
  283.  
  284. /*
  285.  * void SetNewMenus( void )
  286.  * 
  287.  * Gibt die Menus frei, erzeugt sie neu und setzt sie.
  288.  */
  289.  
  290. void SetNewMenus( void )
  291. {
  292.     MyFreeMenus();
  293.  
  294.     if(FileXMenus = CreateMenus(NewMenus, GTMN_FrontPen, 0L, TAG_DONE))
  295.     {
  296.         struct DisplayInhalt *DI;
  297.  
  298.         LayoutMenus(FileXMenus, VisualInfo,GTMN_NewLookMenus,TRUE,TAG_DONE);
  299.  
  300.         DI = (struct DisplayInhalt *)DisplayInhaltList.lh_Head;
  301.  
  302.         while( DI != ( struct DisplayInhalt * )&DisplayInhaltList.lh_Tail )
  303.         {
  304.             if( DI->Wnd )
  305.                 SetMenuStrip(DI->Wnd, FileXMenus);
  306.  
  307.             DI = ( struct DisplayInhalt *)DI->Node.ln_Succ;
  308.         }
  309.  
  310.         SetAllCheckMarks();
  311.     }
  312. }
  313.  
  314. static void SetCheckMark( ULONG MenuID, BOOL status )
  315. {
  316.     struct MenuItem *mi;
  317.  
  318.     if( FileXMenus )
  319.     {
  320.         mi = ItemAddress( FileXMenus, MenuID );
  321.  
  322.         if( status )
  323.             mi->Flags |= CHECKED;
  324.         else
  325.             mi->Flags &= ~CHECKED;
  326.     }
  327. }
  328.  
  329. void SetDisplayCheckMarks( void )
  330. {
  331.     int k;
  332.  
  333.     for( k = 0; k < 4; k++ )
  334.         if( AktuDD->DisplayTyp == k )
  335.             SetCheckMark( displaymenuids[ k ], TRUE );
  336.         else
  337.             SetCheckMark( displaymenuids[ k ], FALSE );
  338. }
  339.  
  340. void SetAllCheckMarks( void )
  341. {
  342.     SetDisplayCheckMarks();
  343. }
  344.  
  345.